﻿using System.Drawing;

namespace SilverlightTetris_M10CDE.Web
{
    /// <summary>
    /// class overview
    /// </summary>
    public class TShape : Shape
    {
        public TShape()
        {
            Block block1 = new Block(8, 0);
            Block block2 = new Block(block1.xPosition, block1.yPosition + 1);
            Block block3 = new Block(block1.xPosition - 1, block2.yPosition);
            Block block4 = new Block(block1.xPosition + 1, block2.yPosition);

            shapeBlock = new Block[4] { block1, block2, block3, block4 };
            orientation = 'n';
            //colour = "Red";
        }

        /// <summary>
        /// Overrides virtual shape method
        /// </summary>
        /// <returns></returns>
        public override Color getColour()
        {
            return (Color.Purple);
        }

        /// <summary>
        /// Reorganize shape block positions after rotation is performed
        /// </summary>
        protected override void SetRotationNorth()
        {
            if (orientation == 'w')
            {
                shapeBlock[0].moveBlock('N');
                shapeBlock[0].moveBlock('E');
                shapeBlock[2].moveBlock('W');
                shapeBlock[2].moveBlock('N');
                shapeBlock[3].moveBlock('E');
                shapeBlock[3].moveBlock('S');
            }
            else //Current rotation must be east (used for un-rotate)
            {
                shapeBlock[0].moveBlock('N');
                shapeBlock[0].moveBlock('W');
                shapeBlock[2].moveBlock('W');
                shapeBlock[2].moveBlock('S');
                shapeBlock[3].moveBlock('E');
                shapeBlock[3].moveBlock('N');
            }
            orientation = 'n';
        }

        /// <summary>
        /// Reorganize shape block positions after rotation is performed
        /// </summary>
        protected override void SetRotationEast()
        {
            if (orientation == 'n')
            {
                shapeBlock[0].moveBlock('E');
                shapeBlock[0].moveBlock('S');
                shapeBlock[2].moveBlock('N');
                shapeBlock[2].moveBlock('E');
                shapeBlock[3].moveBlock('S');
                shapeBlock[3].moveBlock('W');
            }
            else //current rotation must be South (used for un-rotate)
            {
                shapeBlock[0].moveBlock('E');
                shapeBlock[0].moveBlock('N');
                shapeBlock[2].moveBlock('N');
                shapeBlock[2].moveBlock('W');
                shapeBlock[3].moveBlock('S');
                shapeBlock[3].moveBlock('E');
            }
            orientation = 'e';
        }

        /// <summary>
        /// Reorganize shape block positions after rotation is performed
        /// </summary>
        protected override void SetRotationSouth()
        {
            if (orientation == 'e')
            {
                shapeBlock[0].moveBlock('S');
                shapeBlock[0].moveBlock('W');
                shapeBlock[2].moveBlock('E');
                shapeBlock[2].moveBlock('S');
                shapeBlock[3].moveBlock('W');
                shapeBlock[3].moveBlock('N');
            }
            else //Current rotation must be west (used for un-rotate)
            {
                shapeBlock[0].moveBlock('S');
                shapeBlock[0].moveBlock('E');
                shapeBlock[2].moveBlock('E');
                shapeBlock[2].moveBlock('N');
                shapeBlock[3].moveBlock('W');
                shapeBlock[3].moveBlock('S');
            }
            orientation = 's';
        }

        /// <summary>
        /// Reorganize shape block positions after rotation is performed
        /// </summary>
        protected override void SetRotationWest()
        {
            if (orientation == 's')
            {
                shapeBlock[0].moveBlock('W');
                shapeBlock[0].moveBlock('N');
                shapeBlock[2].moveBlock('S');
                shapeBlock[2].moveBlock('W');
                shapeBlock[3].moveBlock('N');
                shapeBlock[3].moveBlock('E');
            }
            else //Current rotation must be north (used for un-rotate)
            {
                shapeBlock[0].moveBlock('W');
                shapeBlock[0].moveBlock('S');
                shapeBlock[2].moveBlock('S');
                shapeBlock[2].moveBlock('E');
                shapeBlock[3].moveBlock('N');
                shapeBlock[3].moveBlock('W');
            }
            orientation = 'w';
        }



    }
}